class Group < Entity
	has_many :administrates
	has_many :admins, :through => :administrates, :source => :entity
	
	#validates :admins, :presence => true	
	
	def ensure_admin_is_created(founder_id)
		Administrate.create(:group_id => self.id, :entity_id => founder_id)		
	end
	
	def ensure_friendship_is_created(founder_id)
		friend = Friendship.create(:entity_id => founder_id, :friend_id => self.id)
		friend.update_attributes(:accepted => true)
	end
	
	def initialise_relationships(founder_id)
		ensure_friendship_is_created(founder_id)
		ensure_admin_is_created(founder_id)
	end
end
